
Partial Class SAD_SQAbout
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim oReportFactory As New SQLAutoDocLib.ReportSchedule_Factory

        If IsPostBack = False Then
            '---Get configuration options
            Dim oConfiguration As New SQLAutoDocLib.Config_Factory

            txtSMTP.Value = oConfiguration.GetValueFromName("MAIL_SMTP")
            txtUID.Value = oConfiguration.GetValueFromName("MAIL_USR")
            txtPWD.Value = oConfiguration.GetValueFromName("MAIL_PWD")
            txtFrom.Value = oConfiguration.GetValueFromName("MAIL_SENDER")
            txtTo.Value = oConfiguration.GetValueFromName("MAIL_RECIPIENT")

            txtServiceInterval.Value = oConfiguration.GetValueFromName("SERVICE_INTERVAL")
            txtSizeRetention.Value = oConfiguration.GetValueFromName("SIZE_RETENTION_PERIOD")
            txtBlockingRetention.Value = oConfiguration.GetValueFromName("BLOCKING_RETENTION_PERIOD")
            txtConnectionRetention.Value = oConfiguration.GetValueFromName("CONNECTION_RETENTION_PERIOD")
            txtWaitstateRetention.Value = oConfiguration.GetValueFromName("WAITSTATE_RETENTION_PERIOD")
            txtSizeTimeout.Value = oConfiguration.GetValueFromName("SIZE_SCAN_TIMEOUT_PERIOD")
            txtBlockingTimeout.Value = oConfiguration.GetValueFromName("BLOCK_SCAN_TIMEOUT_PERIOD")
            txtConnectionTimeout.Value = oConfiguration.GetValueFromName("CONNECTION_SCAN_TIMEOUT_PERIOD")
            txtWaitStateTimeout.Value = oConfiguration.GetValueFromName("WAITSTATE_SCAN_TIMEOUT_PERIOD")

            txtRootURL.Value = oConfiguration.GetValueFromName("ROOT_URL")

            '---Get SQLAutoDoc report options
            Dim oReport As SQLAutoDocLib.ReportSchedule = oReportFactory.GetReportForSystem

            If Not oReport Is Nothing Then
                '---System report has already been defined.
                chkIsActive.Checked = oReport.IsActive

                '---Defaults
                Dim iHour As Integer
                Dim iMinute As Integer
                Dim bIsPM As Boolean
                oReport.GetTimeOfDay(iHour, iMinute, bIsPM)

                txtDelayDays.Value = oReport.DelayDays
                txtHour.Value = iHour
                txtMinute.Value = iMinute
                If bIsPM = False Then
                    rdAM.Checked = True
                Else
                    rdPM.Checked = True
                End If

                txtServerReportEmail.Value = oConfiguration.GetValueFromName("MAIL_RECIPIENT")

            Else
                '---No report has been defined yet.
                chkIsActive.Checked = False

                '---Defaults
                txtDelayDays.Value = 1
                txtHour.Value = "00"
                txtMinute.Value = "00"
                rdAM.Checked = True

                txtServerReportEmail.Value = oConfiguration.GetValueFromName("MAIL_RECIPIENT")
            End If

        ElseIf hidToolbarAction.Value = "newsvr" Then
            Response.Redirect("SQServerE.aspx")

        ElseIf hidToolbarAction.Value = "update" Then
            Dim oConfiguration As New SQLAutoDocLib.Config_Factory

            oConfiguration.SetValueFromName("MAIL_SMTP", txtSMTP.Value)
            oConfiguration.SetValueFromName("MAIL_USR", txtUID.Value)
            oConfiguration.SetValueFromName("MAIL_PWD", txtPWD.Value)
            oConfiguration.SetValueFromName("MAIL_SENDER", txtFrom.Value)
            oConfiguration.SetValueFromName("MAIL_RECIPIENT", txtTo.Value)

            oConfiguration.SetValueFromName("SERVICE_INTERVAL", txtServiceInterval.Value)
            oConfiguration.SetValueFromName("SIZE_RETENTION_PERIOD", txtSizeRetention.Value)
            oConfiguration.SetValueFromName("BLOCKING_RETENTION_PERIOD", txtBlockingRetention.Value)
            oConfiguration.SetValueFromName("CONNECTION_RETENTION_PERIOD", txtConnectionRetention.Value)
            oConfiguration.SetValueFromName("WAITSTATE_RETENTION_PERIOD", txtWaitstateRetention.Value)
            oConfiguration.SetValueFromName("SIZE_SCAN_TIMEOUT_PERIOD", txtSizeTimeout.Value)
            oConfiguration.SetValueFromName("BLOCK_SCAN_TIMEOUT_PERIOD", txtBlockingTimeout.Value)
            oConfiguration.SetValueFromName("CONNECTION_SCAN_TIMEOUT_PERIOD", txtConnectionTimeout.Value)
            oConfiguration.SetValueFromName("WAITSTATE_SCAN_TIMEOUT_PERIOD", txtWaitStateTimeout.Value)
            oConfiguration.SetValueFromName("ROOT_URL", txtRootURL.Value)

            oReportFactory.SetReportValue( _
                                SQLAutoDocLib.ReportSchedule.NODATA, _
                                SQLAutoDocLib.ReportSchedule.NODATA, _
                                txtDelayDays.Value, _
                                txtHour.Value, _
                                txtMinute.Value, _
                                rdPM.Checked, _
                                txtServerReportEmail.Value)

        ElseIf hidToolbarAction.Value = "testmessage" Then
            Dim oMail As New SQLAutoDocLib.SADSendMail( _
                                                txtSMTP.Value, _
                                                txtUID.Value, _
                                                txtPWD.Value)
            Dim sResult As String = oMail.SendMessage( _
                        "Test message from SQLAutoDoc", _
                        "Test message from SQLAutoDoc", _
                        txtFrom.Value, _
                        txtTo.Value)

            If sResult > "" Then
                errSend.InnerText = sResult
                errSend.Visible = True
            Else
                errSend.Visible = False
            End If
        End If

    End Sub
End Class
